package com.java.multipledatasource.thread;

/**
 * @author hu
 * @version 1.0
 * @date 2021/1/19 0019 上午 8:35
 * @description 停止线程 使用 interrupt
 */
public class ThreadStop {

    static class Thread01 implements Runnable{
        int count = 0;
        @Override
        public void run() {
            while (!Thread.currentThread().isInterrupted()) {

                count++;
                System.out.println(Thread.currentThread().isInterrupted());
                System.out.println(count);

            }
        }
    }
    static class Thread02 implements Runnable{
        @Override
        public void run() {

        }
    }

    public static void main(String[] args) {
        Thread thread = new Thread(new Thread01());
        thread.start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        thread.interrupt();

    }
}
